<template>
  <div class="mod-config">
    <h2 style="text-align: center;">添加球员信息</h2>

    <el-steps :active="2" process-status="wait" align-center style="margin-bottom: 40px;">
      <el-step title="球员信息"/>
      <el-step title="球员常规赛进阶数据基础数据"/>
      <el-step title="球员常规赛进阶数据进阶数据"/>
    </el-steps>

    <el-form  :model="list" label-width="100px"
    width="100" :inline="true" class="demo-form-inline" style="margin-left:10%">
  <el-form-item label="场均得分" >
    <el-input v-model="list.score" ></el-input>
  </el-form-item>
  <el-form-item label="场均篮板">
    <el-input v-model="list.rebounds"></el-input>
  </el-form-item>
  <el-form-item label="场均助攻">
    <el-input v-model="list.assists"></el-input>
  </el-form-item>
   <el-form-item label="场均抢断">
    <el-input v-model="list.steals"></el-input>
  </el-form-item>
  <el-form-item label="场均盖帽">
    <el-input v-model="list.blockedShots"></el-input>
  </el-form-item>
  <el-form-item label="出场时间">
    <el-input v-model="list.playingTime"></el-input>
  </el-form-item>
  <el-form-item label="出场数">
     <el-input v-model="list.appearances"></el-input>
  </el-form-item>
   <el-form-item label="场均犯规">
    <el-input v-model="list.foul"></el-input>
  </el-form-item>
   <el-form-item label="场均失误" >
      <el-input v-model="list.fault" ></el-input>
    </el-form-item>
   <el-form-item label="场均投篮数">
    <el-input v-model="list.shotNumber"></el-input>
  </el-form-item>
   <el-form-item label="投篮命中率">
    <el-input v-model="list.shotPercentage"></el-input>
  </el-form-item>
   <el-form-item label="三分命中率">
    <el-input v-model="list.threePercentage"></el-input>
  </el-form-item>
   <el-form-item label="三分命中数">
    <el-input v-model="list.threeNumber"></el-input>
  </el-form-item>
  <el-form-item label="罚球数">
    <el-input v-model="list.freeshotNumber"></el-input>
  </el-form-item>
   <el-form-item label="赛季">
    <el-input v-model="list.season"></el-input>
  </el-form-item>
   <el-form-item label="罚球命中率">
    <el-input v-model="list.freeshotPercentage"></el-input>
  </el-form-item>
   <el-form-item label="常规赛/季后赛/总决赛">
    <el-input v-model="list.stage"></el-input>
  </el-form-item>
    <br>
  <el-form-item class="b" style="margin-left:30%">
            <el-button @click="previous">上一步</el-button>
            <el-button type="primary" @click="saveOrUpdate">保存并下一步</el-button>
        </el-form-item>
</el-form>
 </div>
</template>
<script>
export default {
    data() {
      return {
          list:{
          id: '',
          playerId: '',
          score: '',
          rebounds: '',
          assists: '',
          steals: '',
          blockedShots: '',
          playingTime: '',
          appearances: '',
          foul: '',
          fault: '',
          shotNumber: '',
          shotPercentage: '',
          threePercentage: '',
          threeNumber: '',
          freeshotNumber: '',
          season: '',
          freeshotPercentage: '',
          stage: ''
          }
      }
    },
    created(){
        if(this.$route.params && this.$route.params.id) {
           this.list.playerId=this.$route.params.id
           this.getbasicdateById()
        }
    },
    // beforeMounted(){
    //   if(this.$route.params && this.$route.params.id) {
    //        this.list.playerId=this.$route.params.id
    //        this.getbasicdateById()
    //     }
    // },
     watch:{
          '$route'(to,from){
           if(this.$route.params && this.$route.params.id) {
           this.list.playerId=this.$route.params.id
           this.getbasicdateById()
            }
            }
        },
    methods: {
        addbasicdate(){
          this.$http({
          url: this.$http.adornUrl('/player/playerbasicdate/save'),
          method: 'post',
          data:this.list
        }).then(({data}) => {
               this.$message({
                    type:'success',
                    message:'添加球员基本数据成功！'
                });
               this.$router.push({
                 path:'/player/player-update-advanced/'+this.$route.params.id
               });
        })
        },
          updatebasicdate(){
          this.$http({
          url: this.$http.adornUrl('/player/playerbasicdate/update'),
          method: 'post',
          data:this.list
        }).then(({data}) => {
               this.$message({
                    type:'success',
                    message:'修改球员基本数据成功！'
                });
               this.$router.push({
                 path:'/player/player-update-advanced/'+this.$route.params.id
               });
        })
        },
          saveOrUpdate(){
            if(this.list.id ==''){
                this.addbasicdate()
            }else{
                this.updatebasicdate()
            }
         
        },
        previous() {
            this.$router.push({
                 path:'/player/player-update-information/'+this.$route.params.id
               });
        },
         getbasicdateById(){
          this.$http({
          url: this.$http.adornUrl(`/player/playerbasicdate/infoByPlayerId/${this.$route.params.id}`),
          method: 'post'
        }).then(({data}) => {
          if(data.playerBasicdate!=null){
              this.list = data.playerBasicdate
              console.log(this.list)
              }
             
        })
    }
    }
  }
</script>
<style>

</style>